package cn.lingyangwl.agile.infra.module.dict;

import cn.lingyangwl.agile.infra.module.dict.model.entity.DictItem;
import cn.lingyangwl.framework.core.response.Resp;
import cn.lingyangwl.framework.core.response.RetOps;
import cn.lingyangwl.framework.tool.core.CollectionUtils;
import cn.lingyangwl.framework.tool.core.exception.BizException;
import com.alibaba.cloud.nacos.NacosServiceAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.cloud.openfeign.FeignAutoConfiguration;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Collections;
import java.util.List;
import java.util.Map;

/**
 * @author shenguangyang
 */
@Service
@ConditionalOnClass({FeignAutoConfiguration.class, NacosServiceAutoConfiguration.class})
public class DictItemCloudApiImpl implements DictItemApi {
    @Resource
    private FeignDictItemService feignDictItemService;
    @Override
    public Map<String, Map<String, DictItem>> listByTypes(List<String> types) {
        if (CollectionUtils.isEmpty(types)) {
            return Collections.emptyMap();
        }
        Resp<Map<String, Map<String, DictItem>>> resp = feignDictItemService.listByTypes(types);
        RetOps.of(resp).assertSuccess((e) -> new BizException(e.getCode(), e.getMsg()));
        return resp.getData();
    }

    @Override
    public DictItem getDictItem(String dictType, String dictCode) {
        throw new UnsupportedOperationException("为了保证效率, 这里没有实现远程接口, 调用方需要引入dict-biz依赖");
    }

    @Override
    public List<DictItem> listDictItem(String dictCode) {
        throw new UnsupportedOperationException("为了保证效率, 这里没有实现远程接口, 调用方需要引入dict-biz依赖");
    }
}
